package com.hxzy.controller.userinfo;

import com.alibaba.fastjson.JSONObject;
import com.hxzy.common.BaseServlet;
import com.hxzy.common.ResultAjax;
import com.hxzy.entity.UserInfo;
import com.hxzy.service.UserInfoService;
import com.hxzy.service.impl.UserInfoServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Set;

/**
 * @Description:
 * @Author: ykj
 * @Date: 2022/3/1 20:49
 */
@WebServlet(urlPatterns = "/userinfo/delete")
public class DeleteServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        try {
            UserInfo userInfo = super.CollectiongParameterVlues(req, UserInfo.class);
                UserInfoService userInfoService=new UserInfoServiceImpl();
                int delete = userInfoService.delete(userInfo.getId());
                ResultAjax resultAjax=null;
                if (delete>0){
                    resultAjax=ResultAjax.success("删除成功");
                }else {
                    resultAjax=ResultAjax.success("删除失败");
                }
                super.render(resp, JSONObject.toJSONString(resultAjax));

        } catch (InstantiationException e) {
            e.printStackTrace();
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }

    }
}
